#include "cameracodestate.h"
#include "currentdeviceinfo.h"

CameraCodeState::CameraCodeState(KylinCamera *camera)
{
    cameraCurrent = camera;
}
void CameraCodeState::setFlag(bool res){
    flag = res;
}
void CameraCodeState::run()
{
    enum CameraState state;
    struct stat s_stat;
    memset(&s_stat,0x00,sizeof(struct stat));
    char* devName = cameraCurrent->device_info.dev_name;

    while(1)
    {
        QThread::msleep(100);//为了保证录像文件遇到特殊操作不损坏，录像结束后每隔1s读一下摄像头编码状态，直到编码结束才退出线程
        int ret = stat(devName,&s_stat);  //获取文件信息
        if(ret == -1){
            return;
        }else{
            state = cameraCurrent->camera_get_state(CAMERA_ENCODE);
        }
        qDebug() << "111camera state:" <<state;
        if(state == CAMERA_ENCODE_STOP) break;
        else continue;
    }
    if(flag){
    }else{
        qDebug() << "视频在正常情况下结束录制！" <<state;
    }
    Q_EMIT camerafinish();
}

